﻿using System;
using System.Windows.Input;

namespace Thinktecture.UIAnnotations.Behaviors
{
    public class GenericHandler<TEventArgs>
    {
        private ICommand _command;
        private object _commandParams;

        public GenericHandler(
            ICommand command,
            object commandParams)
        {
            _command = command;
            _commandParams = commandParams;
        }

        public void OnCompleted(object sender, TEventArgs e)
        {
            var parms = (_commandParams != null) ? _commandParams : sender;
            if (_command.CanExecute(parms))
                _command.Execute(parms);
        }
    }
}
